const express = require("express")
const app = express()
app.use(express.static("public"))

app.get("/index",(req,res) => {
    console.log(req.method)
    console.log(req.url)
    console.log(req.httpVersion)
    console.log(req.headers["host"])
    const {a, b} = req.query
    console.log("query", a, b)
    res.send("get 返回数据")
})

const allUser = [
    {id: 1, name: "tom", age: 12},
]

app.get("/uesr/:id", (req,res) => {
    const {id} = req.params
    const user = allUsers.find(user => user.id === + id)
    res.send(user)
})

app.post("index",(req,res) => {
    console.log();
    console.log("body参数",req,body)
    res.send("post 返回数据")
})

app.listen("8080",() => {
    console.log("服务器启动: http://127.0.0.1:8080");
})
